#include "Frm02.h"

Frm02::Frm02(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm02::~Frm02() {
}

void Frm02::onInit() {

}

void Frm02::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- Image : wMImage1                     -----------------------------*/
	wMImage1 = new STTImage(p_rt, this, "wMImage1");
	wMImage1->setMainArg(-5, -195, 1000, 1000);
	wMImage1->addStateImg("0", "./images/img17452811625250_1000X1000R0.png");

	/*----------------------------- Timer : wMTimer1                     -----------------------------*/
	wMTimer1 = new STTTimer(p_rt, this, "wMTimer1", false);
	wMTimer1->set(1000, 0)->start();
	wMTimer1->onEventHandler(Event::READY, this, (EHandler) & Frm02::wMTimer1_timer_cb);

	/*----------------------------- Image : wMImage2                     -----------------------------*/
	wMImage2 = new STTImage(p_rt, this, "wMImage2");
	wMImage2->setMainArg(245, 55, 500, 500);
	wMImage2->addStateImg("0", "./images/img17452831097210_500X500R0.png");

	/*----------------------------- Button : wMButton2                   -----------------------------*/
	wMButton2 = new STTButton(p_rt, this, "wMButton2", 0);
	wMButton2->setMainArg(1, 1, 98, 48, false);
	wMButton2->setPressedArg("返回主页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton2->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton2->setReleasedArg("返回主页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton2->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton2->bindOpenFormHandler(Event::CLICKED, "Frm03", PageMode::NEWWIN, NULL);

	/*called after widget created.*/

	return; //createParts END
}

static void valuecb(void* obj, int32_t v) {
	STTImage* widget = (STTImage*)obj;
	widget->setY(v);//Y坐标不停的变化
}

static void valuecb2(void* obj, int32_t v) {
	STTImage* widget = (STTImage*)obj;
	widget->setAngle(v);
}


void Frm02::onLoad() {
	wMImage1->align(stt::constant::ALIGN::CENTER, 0, 0);
}

bool Frm02::onClosing() {
	return true;
}

void Frm02::onDispose() {

}
static int lasty = 0;
static int lasta = 0;
void Frm02::wMTimer1_timer_cb(uint16_t code, LvEvent e) {
	int iy = std::rand() % 101 - 50;
	wMImage1->getStyle()->p_anim->doAnim(wMImage1, lasty, iy, 1000, valuecb, NULL, 0);
	lasty = iy;
	int ia = std::rand() % 121 - 60;
	cout<<lasta<<"  "<<ia<<endl;
	wMImage1->getStyle()->p_anim->doAnim(wMImage1, lasta, ia, 1000, valuecb2, NULL, 0);
	lasta = ia;
}
